<template>
  <!-- 地图页面组件，展示游戏世界的各个区域 -->
  <div class="map-container">
    
    <h2>世界地图</h2>
    
    <!-- 凡人区域卡片 -->
    <el-card class="area-section">
      <template #header>
        <div class="card-header">
          <span>凡人区域</span>
        </div>
      </template>
      <div class="area-grid">
        <!-- 循环显示凡人区域 -->
        <div class="area-grid-wrapper">
          <el-card 
            v-for="(area, index) in mortalAreas" 
            :key="area.name" 
            :class="['area-card', { 'explored': area.explored }]"
            @click="selectArea(area)"
            :data-index="index"
          >
            <div class="area-content">
              <!-- 区域名称 -->
              <h3>{{ area.name }}</h3>
              <!-- 区域描述 -->
              <p>{{ area.description }}</p>
              <!-- 区域标签 -->
              <div class="area-tags">
                <el-tag size="small" type="success">{{ area.recommendedRealm }}</el-tag>
                <el-tag size="small" :type="getDangerTagType(area.dangerLevel)">{{ area.dangerLevel }}</el-tag>
              </div>
            </div>
          </el-card>
        </div>
      </div>
    </el-card>

    <!-- 修仙区域卡片 -->
    <el-card class="area-section">
      <template #header>
        <div class="card-header">
          <span>修仙区域</span>
        </div>
      </template>
      <div class="area-grid">
        <!-- 循环显示修仙区域 -->
        <div class="area-grid-wrapper">
          <el-card 
            v-for="(area, index) in cultivationAreas" 
            :key="area.name" 
            :class="['area-card', { 'explored': area.explored }]"
            @click="selectArea(area)"
            :data-index="index"
          >
            <div class="area-content">
              <!-- 区域名称 -->
              <h3>{{ area.name }}</h3>
              <!-- 区域描述 -->
              <p>{{ area.description }}</p>
              <!-- 区域标签 -->
              <div class="area-tags">
                <el-tag size="small" type="success">{{ area.recommendedRealm }}</el-tag>
                <el-tag size="small" :type="getDangerTagType(area.dangerLevel)">{{ area.dangerLevel }}</el-tag>
              </div>
            </div>
          </el-card>
        </div>
      </div>
    </el-card>

    <!-- 秘境区域卡片 -->
    <el-card class="area-section">
      <template #header>
        <div class="card-header">
          <span>秘境区域</span>
        </div>
      </template>
      <div class="area-grid">
        <!-- 循环显示秘境区域 -->
        <div class="area-grid-wrapper">
          <el-card 
            v-for="(area, index) in secretAreas" 
            :key="area.name" 
            :class="['area-card', { 'explored': area.explored }]"
            @click="selectArea(area)"
            :data-index="index"
          >
            <div class="area-content">
              <!-- 区域名称 -->
              <h3>{{ area.name }}</h3>
              <!-- 区域描述 -->
              <p>{{ area.description }}</p>
              <!-- 区域标签 -->
              <div class="area-tags">
                <el-tag size="small" type="success">{{ area.recommendedRealm }}</el-tag>
                <el-tag size="small" :type="getDangerTagType(area.dangerLevel)">{{ area.dangerLevel }}</el-tag>
              </div>
            </div>
          </el-card>
        </div>
      </div>
    </el-card>

    <!-- 禁地区域卡片 -->
    <el-card class="area-section">
      <template #header>
        <div class="card-header">
          <span>禁地区域</span>
        </div>
      </template>
      <div class="area-grid">
        <!-- 循环显示禁地区域 -->
        <div class="area-grid-wrapper">
          <el-card 
            v-for="(area, index) in forbiddenAreas" 
            :key="area.name" 
            :class="['area-card', { 'restricted': area.restricted }]"
            @click="selectArea(area)"
            :data-index="index"
          >
            <div class="area-content">
              <!-- 区域名称 -->
              <h3>{{ area.name }}</h3>
              <!-- 区域描述 -->
              <p>{{ area.description }}</p>
              <!-- 区域标签 -->
              <div class="area-tags">
                <el-tag size="small" type="success">{{ area.recommendedRealm }}</el-tag>
                <el-tag size="small" :type="getDangerTagType(area.dangerLevel)">{{ area.dangerLevel }}</el-tag>
                <!-- 限制标签 -->
                <el-tag v-if="area.restricted" size="small" type="danger">{{ area.restriction }}</el-tag>
              </div>
            </div>
          </el-card>
        </div>
      </div>
    </el-card>

    <!-- 区域详情对话框 -->
    <el-dialog v-model="dialogVisible" :title="selectedArea?.name" width="90%" max-width="500px">
      <div v-if="selectedArea" class="area-detail">
        <!-- 区域描述 -->
        <p>{{ selectedArea.description }}</p>
        <!-- 推荐境界 -->
        <p>推荐境界：{{ selectedArea.recommendedRealm }}</p>
        <!-- 危险等级 -->
        <p>危险等级：{{ selectedArea.dangerLevel }}</p>
      </div>
      <template #footer>
        <span class="dialog-footer">
          <el-button @click="dialogVisible = false">取消</el-button>
          <el-button type="primary" @click="enterArea">进入区域</el-button>
        </span>
      </template>
    </el-dialog>
  </div>
</template>

<script>
// 导入响应式引用和响应式对象功能
import { ref, reactive } from 'vue'

export default {
  name: 'Map',
  setup() {
    // 当前位置
    const currentLocation = ref('青云山脚')
    // 控制区域详情对话框显示
    const dialogVisible = ref(false)
    // 当前选中的区域
    const selectedArea = ref(null)

    // 凡人区域数据
    const mortalAreas = ref([
      { name: '青云镇', explored: true, description: '修仙者的起点小镇', recommendedRealm: '练气期', dangerLevel: '安全' },
      { name: '清风村', explored: true, description: '宁静的小村庄', recommendedRealm: '练气期', dangerLevel: '安全' },
      { name: '石桥镇', explored: false, description: '商业发达的城镇', recommendedRealm: '练气期', dangerLevel: '低危' }
    ])

    // 修仙区域数据
    const cultivationAreas = ref([
      { name: '青云山脚', explored: true, description: '你的修行之地', recommendedRealm: '练气期', dangerLevel: '安全' },
      { name: '青云山腰', explored: false, description: '灵气充沛的山腰', recommendedRealm: '筑基期', dangerLevel: '低危' },
      { name: '翠竹林', explored: false, description: '幽静的竹林', recommendedRealm: '筑基期', dangerLevel: '中危' },
      { name: '瀑布崖', explored: false, description: '险峻的瀑布', recommendedRealm: '金丹期', dangerLevel: '高危' }
    ])

    // 秘境区域数据
    const secretAreas = ref([
      { name: '无名洞府', explored: false, status: '未探索', description: '神秘的洞府', recommendedRealm: '筑基期', dangerLevel: '未知' },
      { name: '灵泉洞', explored: false, status: '未探索', description: '有灵泉的洞穴', recommendedRealm: '金丹期', dangerLevel: '未知' }
    ])

    // 禁地区域数据
    const forbiddenAreas = ref([
      { name: '万妖谷', explored: false, restricted: true, restriction: '筑基期禁入', description: '妖兽聚集之地', recommendedRealm: '元婴期+', dangerLevel: '极高' },
      { name: '天魔域', explored: false, restricted: true, restriction: '金丹期禁入', description: '魔气弥漫的领域', recommendedRealm: '化神期+', dangerLevel: '致命' }
    ])

    // 选择区域方法
    const selectArea = (area) => {
      selectedArea.value = area
      dialogVisible.value = true
    }

    // 进入区域方法
    const enterArea = () => {
      console.log('进入区域:', selectedArea.value.name)
      dialogVisible.value = false
    }

    // 根据危险等级获取标签类型
    const getDangerTagType = (dangerLevel) => {
      switch(dangerLevel) {
        case '安全': return 'success'
        case '低危': return ''
        case '中危': return 'warning'
        case '高危': return 'danger'
        case '极高': return 'danger'
        case '致命': return 'danger'
        default: return ''
      }
    }
    
    // 返回数据和方法供模板使用
    return {
      currentLocation,
      dialogVisible,
      selectedArea,
      mortalAreas,
      cultivationAreas,
      secretAreas,
      forbiddenAreas,
      selectArea,
      enterArea,
      getDangerTagType
    }
  }
}
</script>

<style scoped>
/* 地图页面容器样式 */
.map-container {
  padding: 20px;
  overflow-y: auto;
  scrollbar-width: none;
  -webkit-scrollbar: none;
  max-width: 800px;
  margin: 0 auto;
  padding-bottom: 70px;
  padding-top: 50px;
}

/* 区域网格布局样式 */
.area-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 15px;
  padding: 10px 0;
}

/* 区域网格包装器样式 */
.area-grid-wrapper {
  display: contents;
}

/* 区域卡片样式 */
.area-card {
  cursor: pointer;
  transition: all 0.3s;
}

/* 已探索区域卡片样式 */
.area-card.explored {
  background-color: #f0f9ff;
}

/* 受限区域卡片样式 */
.area-card.restricted {
  background-color: #fef0f0;
  opacity: 0.7;
}

/* 区域内容样式 */
.area-content h3 {
  margin: 0 0 10px 0;
  font-size: 16px;
}

/* 区域描述样式 */
.area-content p {
  margin: 0 0 10px 0;
  font-size: 14px;
  color: #666;
}

/* 区域标签容器样式 */
.area-tags {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
}

/* 区域详情样式 */
.area-detail p {
  margin: 10px 0;
}

/* 移动端适配 */
@media screen and (max-width: 768px) {
  .map-container {
    padding: 10px;
    padding-bottom: 70px;
    padding-top: 45px;
  }
  
  .area-grid {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 10px;
  }
  
  .area-content h3 {
    font-size: 15px;
  }
  
  .area-content p {
    font-size: 13px;
  }
}

@media screen and (max-width: 480px) {
  .map-container {
    padding-top: 40px;
  }
  
  .area-grid {
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    gap: 8px;
  }
  
  .area-content h3 {
    font-size: 14px;
  }
  
  .area-content p {
    font-size: 12px;
  }
}

/* 移除了所有动画样式 */
</style>